package com.wangzhy.spider.controller;

import com.wangzhy.common.bean.Result;
import com.wangzhy.common.util.DownloadUtil;
import com.wangzhy.config.DownloadConfig;
import com.wangzhy.spider.service.ISpiderService;
import com.wangzhy.spider.vo.ImgVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：wangzy
 * @date ：  2021/9/16 10:17
 * @description： 抓取控制器
 */
@RestController("/spider")
@Api(tags = "图片抓取")
@Slf4j
public class SpiderController {
    @Autowired
    @Qualifier("spiderService")
    private ISpiderService spiderService;
    @Autowired
    private DownloadConfig downloadConfig;

    @ApiOperation("下载首页配置图片")
    @GetMapping("/spiderHomepageImg")
    public Result spiderHomepageImg(){
        List<ImgVo> list = spiderService.selectPageLayoutImgList();
        DownloadUtil.downloadImgs(list);
        return Result.success("首页图片下载");
    }

    @ApiOperation("下载app首页品类设置图片")
    @GetMapping("/spiderAppHomeConfigImg")
    public Result spiderAppHomeConfigImg(){
        List<ImgVo> list = spiderService.selectAppHomeConfigImgList();
        DownloadUtil.downloadImgs(list);
        return Result.success("下载app首页品类设置图片成功");
    }
    @ApiOperation("下载商品图片")
    @GetMapping("/spiderMerchandiseImg")
    public Result spiderMerchandiseImg(){
        return spiderService.spiderMerchandisePic();
    }




}
